package com.ctrip.ec.biz.kuaidi;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.util.HashMap;

/**
 * Created by jiangzy on 2018/12/17.
 */
public class Demo {
    public static void main(String[] args) {
        String com = "shentong";
        String num = "3390773922071";
        String param ="{\"com\":\""+ com + "\",\"num\":\""+ num + "\"}";
        String customer ="31E362AEA4850A8B617BC68CA5FB155E";
        String key = "ghRXfeuU5067";
        String sign = MD5.encode(param+key+customer);
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("param",param);
        params.put("sign",sign);
        params.put("customer",customer);

        String resp;
        try {
            resp = new HttpRequest().postData("http://poll.kuaidi100.com/poll/query.do", params, "utf-8").toString();
            System.out.println(resp);

            JsonObject jsonObject = new JsonParser().parse(resp).getAsJsonObject();
            JsonArray array = jsonObject.getAsJsonArray("data");


            for(int i=0;i<array.size() ;i++){
                JsonElement element = array.get(i);
                System.out.println(element.toString());
            }


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

//    {"message":"ok","nu":"3390773922071","ischeck":"1","condition":"D01","com":"shentong","status":"200","state":"3","data":[{"time":"2018-12-18 13:55:48","ftime":"2018-12-18 13:55:48","context":"门卫-已签收"},{"time":"2018-12-18 10:02:02","ftime":"2018-12-18 10:02:02","context":"河南周口公司-刘磊(0394-7978919)-派件中"},{"time":"2018-12-18 09:17:02","ftime":"2018-12-18 09:17:02","context":"已到达-河南周口公司"},{"time":"2018-12-18 07:57:38","ftime":"2018-12-18 07:57:38","context":"已到达-河南周口公司"},{"time":"2018-12-17 14:54:00","ftime":"2018-12-17 14:54:00","context":"河南漯河转运中心-已发往-河南周口公司"},{"time":"2018-12-16 22:09:40","ftime":"2018-12-16 22:09:40","context":"上海航空部-已装袋发往-河南漯河转运中心"},{"time":"2018-12-16 20:04:43","ftime":"2018-12-16 20:04:43","context":"上海梅陇公司-已装袋发往-上海航空部"},{"time":"2018-12-16 19:18:45","ftime":"2018-12-16 19:18:45","context":"上海梅陇公司-已进行装袋扫描"},{"time":"2018-12-16 19:18:45","ftime":"2018-12-16 19:18:45","context":"上海梅陇公司-已发往-上海航空部"},{"time":"2018-12-16 18:25:09","ftime":"2018-12-16 18:25:09","context":"上海梅陇公司-刘桂秀(18202162308)-已收件"}]}
//    {"time":"2018-12-18 13:55:48","ftime":"2018-12-18 13:55:48","context":"门卫-已签收"}
//    {"time":"2018-12-18 10:02:02","ftime":"2018-12-18 10:02:02","context":"河南周口公司-刘磊(0394-7978919)-派件中"}
//    {"time":"2018-12-18 09:17:02","ftime":"2018-12-18 09:17:02","context":"已到达-河南周口公司"}
//    {"time":"2018-12-18 07:57:38","ftime":"2018-12-18 07:57:38","context":"已到达-河南周口公司"}
//    {"time":"2018-12-17 14:54:00","ftime":"2018-12-17 14:54:00","context":"河南漯河转运中心-已发往-河南周口公司"}
//    {"time":"2018-12-16 22:09:40","ftime":"2018-12-16 22:09:40","context":"上海航空部-已装袋发往-河南漯河转运中心"}
//    {"time":"2018-12-16 20:04:43","ftime":"2018-12-16 20:04:43","context":"上海梅陇公司-已装袋发往-上海航空部"}
//    {"time":"2018-12-16 19:18:45","ftime":"2018-12-16 19:18:45","context":"上海梅陇公司-已进行装袋扫描"}
//    {"time":"2018-12-16 19:18:45","ftime":"2018-12-16 19:18:45","context":"上海梅陇公司-已发往-上海航空部"}
//    {"time":"2018-12-16 18:25:09","ftime":"2018-12-16 18:25:09","context":"上海梅陇公司-刘桂秀(18202162308)-已收件"}

}
